﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Hosting;
using System.Web.Security;
using System.Web.SessionState;

namespace WebPackagin2
{
    public class Global : System.Web.HttpApplication
    {
        protected void Session_OnStart(object sender, EventArgs e)
        {
           string path = HostingEnvironment.MapPath("/ClientBin");
           string pathzip = Path.Combine(Path.GetTempPath(), "package" + ".zip");
           if (!File.Exists(Path.Combine(path, "package.zip")))
            {
                File.Delete(pathzip);
                File.Delete(Path.Combine(path, "package.zip"));
                ZipFile.CreateFromDirectory(path, pathzip, CompressionLevel.NoCompression, false, Encoding.ASCII);
                File.Copy(pathzip, Path.Combine(path, "package.zip"), true);
                File.Delete(pathzip);
            }
        }
    }
}